package org.dreamwork.jasmine2.sample.page;

import org.dreamwork.jasmine2.events.EventException;
import org.dreamwork.jasmine2.events.IClickListener;
import org.dreamwork.jasmine2.web.IWebControl;
import org.dreamwork.jasmine2.web.controls.*;
import org.dreamwork.util.VirtualFile;

/**
 * Created by IntelliJ IDEA.
 * User: seth.yang
 * Date: 11-8-31
 * Time: 下午5:19
 */
public class TestControl extends UserControl {
    protected Label label;

    protected FileControl fileControl;
    protected Button btnUpload ;

    @Override
    public void onPageLoad (Page page) throws EventException {
        System.out.println ("page load");
    }

    @Override
    public void onPagePreload (Page page) throws EventException {
        System.out.println ("page preload");
        btnUpload.addClickListener (new IClickListener() {
            public void onClick (IWebControl sender) throws EventException {
                upload ();
            }
        });
    }

    @Override
    public void onPageLoadCompleted (Page page) throws EventException {
        System.out.println ("page load complete");
        label.setText (String.valueOf (System.nanoTime ()));
    }

    @Override
    public void init () {
        super.init ();
        System.out.println ("init ... ");
    }

    private void upload () {
        VirtualFile vf = fileControl.getVirtualFile ();
        System.out.println (vf.getClientPath ());
    }
}